#pragma once
#include "Port_Global.h"
#include <vector>

class GraphicsUtil
{
public:
	GraphicsUtil(void);
	~GraphicsUtil(void);

	void drawToBackBuffer(BITMAP *imageA, const int x, const int y, const int level = 0);

	void drawTransToBackBuffer(BITMAP *imageA, const int x, const int y, const int alpha, const int level = 0)
	{
		if(checkLevel(level))
		{
			set_trans_blender(255, 255, 255, alpha);
			draw_trans_sprite(buffers[level], imageA, x, y);
			solid_mode();
		}
	}

	void drawAlphaToBackBuffer(BITMAP *imageA, const int x, const int y, const int level = 0)
	{
		if(checkLevel(level))
		{
			set_alpha_blender();
			draw_trans_sprite(buffers[level], imageA, x, y);
			solid_mode();
		}
	}

	void clearBufferToColor(short r, short g, short b, const int level = 0)
	{
		if(checkLevel(level))
		{
			clear_to_color(buffers[level] ,makecol(r, g, b));
		}
	}

	void drawTextToBackBuffer(const FONT *f, const char *s, const int x, const int y, const int color, const int bg = -1, const int level = 0)
	{
		if(checkLevel(level))
		{
			textout_ex(buffers[level], f, s, x, y, color, bg);
		}
	}

	void blitToBackBuffer(BITMAP *imageA, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height, const int level = 0)
	{
		if (checkLevel(level))
		{
			blit(imageA, buffers[level], srcX, srcY, dstX, dstY, width, height);
		}
	}

	void clearBuffers()
	{
		for (vector<BITMAP *>::const_iterator itr = buffers.begin(); itr < buffers.end(); ++itr)
		{
			BITMAP *bitmap = static_cast<BITMAP *>(*itr);
			clear_bitmap(bitmap);
			clear_to_color(bitmap ,makecol(0, 0, 0));
		}
	}

	BITMAP *getLevel(const int level)
	{
		if(checkLevel(level))
		{
			return buffers[level];
		}
		return NULL;
	}

	void drawBackBufferToScreen(const int level = 0);
	void fader(BITMAP *imageA, BITMAP *imageB, const int ratio);
private:

	bool checkLevel(int level);
	vector<BITMAP *> buffers;
};
